﻿using ProgrammingEducationSystem.DbConfig;
using ProgrammingEducationSystem.Models;
using Microsoft.EntityFrameworkCore;

namespace ProgrammingEducationSystem.Repository.IRepository
{
    public class LearnSourceRepository : BaseRepository<LearnSource>, ILearnSourceRepository
    {
        public LearnSourceRepository(AppDbCtx appDbCtx) : base(appDbCtx)
        {
        }

        public async Task<List<LearnSource>> GetByCourseTypeIdList(List<Guid> courseTypeIdList)
        {
            return await _appDbCtx.LearnSources.Where(ls=>courseTypeIdList.Contains(ls.CourseTypeId)).ToListAsync();
        }

        public async Task<List<LearnSource>> GetByCourseType(string courseTypeName)
        {
            return await _appDbCtx.LearnSources.Include(ls=>ls.CourseType).Where(ls=>ls.CourseType.Name==courseTypeName).ToListAsync();
        }

        public async Task<List<LearnSource>> GetByCourseType(Guid courseTypeId)
        {
            return await _appDbCtx.LearnSources.Include(ls=>ls.CourseType).Where(ls=>ls.CourseType.Id==courseTypeId).ToListAsync();
        }

        /// <summary>
        /// 由于外键改变，该方法被废弃
        /// </summary>
        /// <param name="classId"></param>
        /// <returns></returns>
        ///// 
        //public async Task<List<LearnSource>> GetByClassIdAsync(Guid classId)
        //{
        //    var crs = await _appDbCtx.Courses.Where(c => c.ClassId == classId).ToListAsync();

        //    var chs = await _appDbCtx.CourseHours.Where(
        //        ch => crs.Any(cr => cr.Id == ch.CourseId)
        //        ).ToListAsync();
        //    return await _appDbCtx.LearnSources.Where(
        //        ls => chs.Any(ch => ch.Id == ls.CourseHourId)
        //        ).ToListAsync();
        //}



        //由于外键修改，该方法被废弃
        //public async Task<List<LearnSource>> GetByCourseHourIdAsync(Guid id)
        //{
        //    return await _appDbCtx.LearnSources.Where(ls => ls.CourseHourId == id).ToListAsync();
        //}

        //由于外键修改，该方法被废弃
        //public async Task<List<LearnSource>> GetByTeacherIdAsync(string id)
        //{
        //    return await _appDbCtx.LearnSources
        //        .Include(ls => ls.CourseHour)
        //        .ThenInclude(ch => ch.Course)
        //        .ThenInclude(c => c.@class)
        //        .Where(ls => ls.CourseHour.Course.@class.TeacherId == id).ToListAsync();
        //}
    }
}
